#include "wc3memory.h"
#include "Extern_global_Variable.h"

Pointer Allocate(PtrUInt Size)
{
	return SMemAlloc(Size, NULL, 0, 0);
}

Pointer ReAllocate(Pointer Memory, PtrUInt NewSize)
{
	return SMemReAlloc(Memory, NewSize, NULL, 0, 0);
}

procedure Free(Pointer Memory)
{
	SMemFree(Memory, NULL, 0, 0);
}

PChar CloneString(PChar s)
{
	PChar Result;
	Integer Length;

	Length = strlen(s);
	Result = (PChar)Allocate((PtrUInt)Length + 1);
	memcpy((Pointer)s, (Pointer)Result, Length);
	Result[Length] = 0;
	return Result;
}

bool fRegistrStorm_1()
{
	HMODULE hStorm;
	hStorm = GetModuleHandle(L"storm.dll");
	if(!hStorm) return FALSE;

	SMemAlloc = (SMemAlloc_1)GetProcAddress(hStorm, "SMemAlloc");
	if(!SMemAlloc) return FALSE;

	SMemFree = (SMemFree_1)GetProcAddress(hStorm, "SMemFree");
	if(!SMemFree) return FALSE;

	SMemReAlloc = (SMemReAlloc_1)GetProcAddress(hStorm, "SMemReAlloc");
	if(!SMemReAlloc) return FALSE;

	return TRUE;
}